package org.jmetrix.group;

import java.util.ArrayList;

/**
 * @author Konstantin Kuzmin
 * @version $Revision$
 * @since 01.10.11
 */
public class GroupSequence {
    private ArrayList<String> groups = new ArrayList<String>();
    private static final ThreadLocal<GroupSequence> GROUP_SEQUENCE = new ThreadLocal<GroupSequence>() {
        @Override
        protected GroupSequence initialValue() {
            return new GroupSequence();
        }
    };

    public static ThreadLocal<GroupSequence> getThreadLocal() {
        return GROUP_SEQUENCE;
    }

    public String[] getGroups() {
        return groups.toArray(new String[groups.size()]);
    }

    public synchronized void add(String group) {
        groups.add(group);
    }

    public synchronized void removeLast() {
        if (!groups.isEmpty()) {
            groups.remove(groups.size() - 1);
        }
    }
}
